package com.a2j.beans.base;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * Author: bzb
 * Data: 2021/11/17 23:07
 * Desc: 分页返回数据
 */
@Data
@ApiModel(description = "分页数据包装类")
public class BasePageBean<T> {

    @ApiModelProperty(value = "总条数")
    private int total; // 总条数

    @ApiModelProperty(value = "总页数")
    private int totalPage; // 总页数

    @ApiModelProperty(value = "指定查询第几页")
    private int page; // 入参指定查询的页数

    @ApiModelProperty(value = "查询多少条")
    private int rows; // 入参指定查询的行数

    @ApiModelProperty(value = "数据集合")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<T> list; // 数据集合

    private BasePageBean() {}

    public static class Builder<T> {
        private final BasePageBean<T> bean;

        public Builder() {
            bean = new BasePageBean<>();
        }

        public Builder<T> page(Integer page) {
            bean.setPage(page);
            return this;
        }

        public Builder<T> rows(Integer rows) {
            bean.setRows(rows);
            return this;
        }

        public Builder<T> total(Integer total) {
            bean.setTotal(total);
            return this;
        }

        public Builder<T> totalPage(Integer totalPage) {
            bean.setTotalPage(totalPage);
            return this;
        }

        public Builder<T> list(List<T> list) {
            bean.setList(list);
            return this;
        }

        public BasePageBean<T> builder() {
            return bean;
        }
    }
}
